package com.libservice.models

import com.libbase.MapCodable
import java.util.*

data class AuthModel(
    val userId: String,
    var accessToken: String,
    val accessTokenType: String,
    var refreshToken: String,
    var expiredTime: Date
) : MapCodable {
    companion object {
        fun create(map: Map<String, Any>): AuthModel? {
            val userId: String = map["userId"] as? String ?: return null
            val accessToken: String = map["accessToken"] as? String ?: return null
            val accessTokenType: String = map["accessTokenType"] as? String ?: return null
            val refreshToken: String = map["refreshToken"] as? String ?: return null
            val expiredTime: Long = map["expiredTime"] as? Long ?: return null

            return AuthModel(
                userId,
                accessToken,
                accessTokenType,
                refreshToken,
                Date(expiredTime)
            )
        }
    }

    override fun toMap(): Map<String, Any> {
        return mapOf(
            "userId" to userId,
            "accessToken" to accessToken,
            "accessTokenType" to accessTokenType,
            "refreshToken" to refreshToken,
            "expiredTime" to expiredTime.time
        )
    }
}